﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class logoff : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bug_Util.do_not_cache(Response);
            Bug_Util.set_context(HttpContext.Current);

            DbUtil.get_sqlconnection();
            // delete the session row
            HttpCookie cookie = Request.Cookies["se_id"];

            if (cookie != null)
            {
                string se_id = cookie.Value.Replace("'", "''");
                string sql = @"delete from sessions where se_id = N'$se' or datediff(d, se_date, getdate()) > 2";
                sql = sql.Replace("$se", se_id);
                DbUtil.execute_nonquery(sql);

                Session[se_id] = 0;
                Session["SelectedBugQuery"] = null;
                Session["bugs"] = null;
                Session["bugs_unfiltered"] = null;
                Session["project"] = null;
            }

            Response.Redirect("default.aspx?msg=logged+off");
        }
    }
}
